package cn.qingyun.gis.modules.scenes.service.impl;

import cn.hutool.json.JSONUtil;
import cn.qingyun.gis.modules.scenes.entity.PoiScenarioProofreadDraft;
import cn.qingyun.gis.modules.scenes.mapper.PoiScenarioProofreadDraftMapper;
import cn.qingyun.gis.modules.scenes.mapper.PoiScenarioProofreadMapper;
import cn.qingyun.gis.modules.scenes.request.PoiDraftRequest;
import cn.qingyun.gis.modules.scenes.request.PoiKwRequest;
import cn.qingyun.gis.modules.scenes.service.PoiScenarioProofreadDraftService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author LHJ
 * @description
 * @date 2024/10/25 17:30
 */
@Slf4j
@Service
@DS("scenes_offensive")
public class PoiScenarioProofreadDraftServiceImpl extends ServiceImpl<PoiScenarioProofreadDraftMapper, PoiScenarioProofreadDraft> implements PoiScenarioProofreadDraftService{

    @Resource
    private PoiScenarioProofreadDraftMapper poiScenarioProofreadDraftMapper;

    @Override
    public void updateDraft(PoiDraftRequest request) {
        String jsonStr = JSONUtil.toJsonStr(request);
        poiScenarioProofreadDraftMapper.updateDraftContent(jsonStr,request.getChainId());
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteTempRecord(PoiKwRequest request) {
        log.debug("{}进入暂存记录删除===",request.getChainId());
        QueryWrapper<PoiScenarioProofreadDraft> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(PoiScenarioProofreadDraft::getKwPhone,request.getKwPhone()).eq(PoiScenarioProofreadDraft::getProofreadId,request.getChainId());
        int delete = poiScenarioProofreadDraftMapper.delete(wrapper);
        log.debug("暂存记录删除的结果{}",delete);
    }
}
